package com.tnsw.noxnox.lab;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.Socket;

import android.content.Context;
import android.util.Log;

public class SimulateGCM extends Thread {
	
	public static String HOST = "172.16.50.192";
	public static int PORT = 1444;
	
	private String tag = "SimulateGCM";
	private static boolean sIsRunning = false;
	private static SimulateGCM sInstance;
	private Context context;
	
	private Socket socket;
	private PrintStream stream = null;
	
	public SimulateGCM(Context context) {
		Log.d(tag, "Constrcutor(context)");
		this.context = context;
		
		Thread t = new Thread(this);
		t.start();
		
		sIsRunning = true;
	}
	
	public static SimulateGCM getInstance(Context context) {
		if (sIsRunning == false) {
			sInstance = new SimulateGCM(context);
			
		}
		
		return(sInstance);
	}
	
	public void run() {
		try {
			this.socket = new Socket(SimulateGCM.HOST, SimulateGCM.PORT);
			this.stream = new PrintStream(this.socket.getOutputStream());
	
			BufferedReader in = null;
			in = new BufferedReader(new InputStreamReader(this.socket.getInputStream()));
			
			String line = "";
			
			while ((line = in.readLine()) != null) {
			    Log.d(tag, "line=" + line);
			}
			
		} catch (Exception e) {
			Log.e(tag, "initialize() - " + e.toString(), e);
		}
	}
	
	public void disconnect() {
		try {
			this.socket.close();	
		} catch (Exception e) {
			Log.e(tag, "disconnect - " + e.toString(), e);
		}
		
	}
	
	

}
